//
//  StatusRetweetedCell.swift
//  新浪微博
//
//  Created by 焦林生 on 15/11/12.
//  Copyright © 2015年 焦林生. All rights reserved.
//

import UIKit
//转发微博cell
class StatusRetweetedCell: StatusCell {

    // 微博视图模型
    override var viewModel: StatusViewModel? {
    
        didSet {
            //转发微博文字
            retweetedLabel.text = viewModel?.retweetedText
        
            //修改配图视图顶部位置
            pictureView.snp_updateConstraints { (make) -> Void in
                //根据配图数量 修改顶部配图视图约束
                let offset = viewModel?.thumbnailUrls?.count == 0 ? 0 : StatusCellMargin
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            }
        }
    }
    
    //MARK: - 懒加载控件
    //背景图片
    private lazy var backButton: UIButton = {
    
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        return button
    }()
    //转发微博标签
    private lazy var retweetedLabel: UILabel = UILabel(title: "可以啊 小少年",
        fontSize: 14,
        color: UIColor.darkGrayColor(),
        screenInset: StatusCellMargin)
    

}
// MARK: - 设置界面
extension StatusRetweetedCell {

    //
    override func setupUI() {
    //调用父类的setupUI 设置父类的控件的位置
        super.setupUI()
        
        //1 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        //添加转发文字
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        
        //2 自动布局
        //1 背景图片
        backButton.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
            
        }
        //2 转发文字标签
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
            
        }
        //3 配图视图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        
    }
}



